/*
 * Copyright (C) 2022 xuexiangjys(xuexiangjys@163.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package cn.kcrx.autoweightapp.fragment

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.LinearLayoutManager
import cn.kcrx.autoweightapp.core.BaseFragment
import cn.kcrx.autoweightapp.databinding.FragmentCashweightSettingBinding
import cn.kcrx.autoweightapp.fragment.adapter.CashWeightSettingAdapter
import cn.kcrx.autoweightapp.fragment.viewmodes.CashWeightSettingVM
import com.xuexiang.xpage.annotation.Page

@Page(name = "原封箱标定重量设置")
class CashWeightSettingFragment:BaseFragment<FragmentCashweightSettingBinding>() {
    private val viewModel:CashWeightSettingVM by viewModels()
    private val adapter=CashWeightSettingAdapter()
    override fun viewBindingInflate(
        inflater: LayoutInflater,
        container: ViewGroup
    ): FragmentCashweightSettingBinding =
        FragmentCashweightSettingBinding.inflate(inflater,container,false)

    override fun initViews() {
        binding!!.rvCashweightSetting.layoutManager=LinearLayoutManager(context)
        binding!!.rvCashweightSetting.adapter=adapter
        binding!!.rvCashweightSetting.itemAnimator=DefaultItemAnimator()

        viewModel.cashWeightSetting.observe(viewLifecycleOwner){
             if(it.size>0)
             {
                 adapter.submitList(it)
             }
            adapter.notifyDataSetChanged()
        }
    }
}